import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.PlayField;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.SpriteGroup;

public class State {

	private PlayField myField;
	private long myTime;

	public State(PlayField field){
		this(field,0);
	}
	
	public State(PlayField field, long time){
		myField = field;
		myTime = time;
	}
	
	public void setTime(long time){
		myTime = time;
	}
	public long getTime(){
		return myTime;
	}
	public PlayField getPlayField(){
		return myField;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/*
	@Override
<<<<<<< .mine
	public boolean equals(Object o){
		State other = (State) o;
=======
	public boolean equals(Object o)
	{
		Class cls1 = State.class;
		Class cls2 = State.class;
		Field[] fields1 = cls1.getDeclaredFields();
		Field[] fields2 = cls2.getDeclaredFields();
		return equalHelper(fields1, fields2, cls1, cls2);
>>>>>>> .r12
		
		Background background = myField.getBackground();
		Background backgroundOther =other.myField.getBackground();
		
		if(!backgroundIsSame(background, backgroundOther)) return false;
		
		
		Comparator groupComparator = new Comparator(){

			@Override
			public int compare(Object a, Object b) {
				return ((SpriteGroup)a).getName().compareTo(((SpriteGroup)b).getName());
			}
			
		};

		List<SpriteGroup> spriteGroup1 = Arrays.asList(myField.getGroups());
		Collections.sort(spriteGroup1, groupComparator);
		List<SpriteGroup> spriteGroup2 = Arrays.asList(other.myField.getGroups());
		Collections.sort(spriteGroup2, groupComparator);
		

		List<Sprite> extraSprites = sortSpriteGroup(myField.getExtraGroup());
		List<Sprite> otherExtraSprites = sortSpriteGroup(other.myField.getExtraGroup());
		
		for(int i = 0; i < extraSprites.size(); i++){
			if(!isSpriteSame(extraSprites.get(i),otherExtraSprites.get(i))) return false;
		}
		
		return true;
		
	}
	
	public boolean isSpriteGroupSame(SpriteGroup a, SpriteGroup b){
		
	}
	
	public List<Sprite> sortSpriteGroup(SpriteGroup group){

		List<Sprite> sortedSprites = Arrays.asList(group.getSprites());
		Collections.sort(sortedSprites,myField.getComparator());
		return sortedSprites;
	}
	
	public boolean isSpriteSame(Sprite a, Sprite b){
		return 
		(a.getBackground() == b.getBackground()) &&
		(a.getX() == b.getX()) && (a.getY() == b.getY()) &&
		(a.getHorizontalSpeed() == b.getHorizontalSpeed()) &&
		(a.getVerticalSpeed() == b.getVerticalSpeed()) &&
		(a.getOldX() == b.getOldX()) && (a.getOldY() == b.getOldY()) &&
		(a.getScreenX() == b.getScreenX()) && (a.getScreenY() == b.getScreenY()) &&
		(a.getImage() == b.getImage()) && (a.getWidth() == b.getWidth()) &&
		(a.getHeight() == b.getHeight()) && (a.getID() == b.getID()) &&
		(a.getDataID() == b.getDataID()) && (a.getLayer() == b.getLayer()) &&
		(a.isActive() == b.isActive()) && (a.isImmutable() == b.isImmutable());
	}
	
	public boolean backgroundIsSame(Background a, Background b){
		return (a.getX() == b.getX()) && (a.getY() == b.getY()) &&
					(a.getHeight() ==  b.getHeight()) && (a.getWidth() == b.getWidth());
	}
	*/
}
